package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.AddressFactory;
import com.egao.orderB.service.AddressFactoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/addressFactory")
@RestController
@Api(value = "货代运费地址",tags = {"货代运费地址"})
public class ApiAddressFactoryController extends BaseController {
    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private AddressFactoryService addressFactoryService;

    /**
     * 运费维护列表
     */
    @PreAuthorize("hasAuthority('orderB:addressFactory:list')")
    @PostMapping("/list")
    @ApiOperation(value = "货代运费地址列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "customerId:客户id \n" +
            "返回的字段:\n" +
            "id:id\n" +
            "organizationId:公司id\n" +
            "addressId:货代费用地址id\n" +
            "faddress:地址\n" +
            "fphone:电话\n" +
            "fstate:状态 默认\n" +
            "fremark:备注\n" +
            "longitude:经度\n" +
            "latitude:纬度\n" +
            "radius:半径\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, AddressFactory addressFactory, HttpServletRequest request)  throws Exception{
        return addressFactoryService.list(page, addressFactory, getLoginUser());
    }

    /**
     * 添加运费维护列表
     */
    @PreAuthorize("hasAuthority('orderB:addressFactory:list')")
    @PostMapping("/listAll")
    @ApiOperation(value = "货代运费地址列表",notes = "" +
            "",httpMethod = "POST")
    public JsonResult listAll(AddressFactory addressFactory, HttpServletRequest request)  throws Exception{
        return addressFactoryService.list(addressFactory, getLoginUser());
    }

    @PreAuthorize("hasAuthority('orderB:addressFactory:list')")
    @PostMapping("/getById")
    @ApiOperation(value = "订单查询",notes = "id ",httpMethod = "POST")
    public JsonResult getById(AddressFactory addressFactory, HttpServletRequest request) {
        return addressFactoryService.getById(addressFactory);
    }


    /**
     * 添加运费报价
     */
    @PreAuthorize("hasAuthority('orderB:addressFactory:save')")
    @OperLog(value = "货代运费地址", desc = "平台添加货代运费地址", result = true)
    @PostMapping("/save")
    @ApiOperation(value = "平台添加货代运费地址",notes = "\n" +
            "addressId:货代费用地址id \n" +
            "customerId:客户id 必填\n" +
            "faddress:地址\n" +
            "fphone:电话\n" +
            "fstate:默认\n" +
            "longitude:经度\n" +
            "latitude:纬度\n" +
            "radius:半径\n" +
            "",httpMethod = "POST")
    public JsonResult save(AddressFactory addressFactory, HttpServletRequest request) {
        return addressFactoryService.save(addressFactory, getLoginUser());
    }

    /**
     * 修改运费报价
     */
    @PreAuthorize("hasAuthority('orderB:addressFactory:update')")
    @OperLog(value = "货代运费地址", desc = "修改货代运费地址", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "修改货代运费地址",notes = "" +
            "id:运费报价id 必填\n" +
            "faddress:地址\n" +
            "fphone:电话\n" +
            "longitude:经度\n" +
            "latitude:纬度\n" +
            "radius:半径\n" +
            "",httpMethod = "POST")
    public JsonResult update(AddressFactory addressFactory, HttpServletRequest request) {
        return addressFactoryService.update(addressFactory, getLoginUser());
    }

    /**
     * 修改运费地址为默认
     */
    @PreAuthorize("hasAuthority('orderB:addressFactory:update')")
    @OperLog(value = "修改运费地址为默认", desc = "修改运费地址为默认", result = true)
    @PostMapping("/updateFstate")
    @ApiOperation(value = "修改运费地址为默认",notes = "" +
            "id:运费报价id 必填\n" +
            "addressId:货代费用地址id 必填\n" +
            "",httpMethod = "POST")
    public JsonResult updateFstate(AddressFactory addressFactory, HttpServletRequest request) {
        return addressFactoryService.updateFstate(addressFactory, getLoginUser());
    }

    /**
     * 删除运费报价
     */
    @PreAuthorize("hasAuthority('orderB:addressFactory:remove')")
    @OperLog(value = "货代运费地址", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "删除货代运费地址",notes = "id:id必填",httpMethod = "POST")
    public JsonResult remove(AddressFactory addressFactory, HttpServletRequest request) {
        return addressFactoryService.remove(addressFactory, getLoginUser());
    }

}
